package org.mineground.commands.irc;

import org.jibble.pircbot.Colors;
import org.jibble.pircbot.User;
import org.mineground.Main;
import org.mineground.handlers.irc.CommandExecutor;
import org.mineground.handlers.irc.UserLevel;

/**
 * @file Raw.java (20.02.2012)
 * @author Daniel Koenen
 *
 */
public class Raw implements CommandExecutor {
    @Override
    public void onCommand(User sender, UserLevel level, String channel, String command, String[] args) {
        if (level.compareTo(UserLevel.IRC_SOP) < 0) {
	    return;
        }
        
        if (args.length < 1) {
            Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "* Usage:" + Colors.NORMAL + " !raw [server command]");
	    return;
	}
        
        String serverCommand;
        StringBuilder serverCommandBuilder = new StringBuilder();
        
        for (int index = 0; index < args.length; index++) {
            serverCommandBuilder.append(args[index]);
            serverCommandBuilder.append(" ");
        }
        
        serverCommand = serverCommandBuilder.toString().substring(0, serverCommandBuilder.toString().length() - 1);
        
        Main.getInstance().getServer().dispatchCommand(Main.getInstance().getServer().getConsoleSender(), serverCommand);
        Main.getInstance().getIRCHandler().sendMessage(channel, Colors.DARK_GREEN + " Executed '" + serverCommand + "'. Do you see a result?");
    }

}
